﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WinformsTest0004
{
    class DbHelper
    {
        private static  readonly string conString = "server=.;database=admin3000;uid=sa;pwd=123456";

        /// <summary>
        /// 获得表格数据
        /// </summary>
        /// <param name="sql">查询 select语句</param>
        /// <returns>表的数据</returns>
        public static DataTable GetDataTable(string sql)
        {
            
            SqlConnection sqlConnection = new SqlConnection(conString);

            string cmdString = "select *from users";

            SqlDataAdapter dataAdapter = new SqlDataAdapter(cmdString, sqlConnection);

            DataTable dt = new DataTable();
            sqlConnection.Open();
            dataAdapter.Fill(dt);
            return dt;
        }
    }
}
